home *** CD-ROM | disk | FTP | other *** search
- /*
- File: RgnShpe.h
-
- Contains: RgnShape class, private to ODShape.
-
- Owned by: Jens Alfke
-
- Copyright: © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <10> 8/29/95 jpa Throw kODErrInvalidPlatformShape if NULL
- region passed in. [12788284]
- <9> 8/16/95 NP 1274946: ErrorDef.idl problems. Add include
- file.
- <8> 8/8/95 jpa Got rid of CATCH(): not native-exceptions
- compatible. [1268187]
- <7> 12/5/94 jpa Implemented CopyGXShape. [1195654]
- <6> 10/24/94 jpa Use RealShape::NewGeometricShape to
- promote. [1195070]
- <5> 9/29/94 RA 1189812: Mods for 68K build.
- <4> 9/14/94 jpa Outset converts distance to short before
- calling InsetRgn. [1183857]
- <3> 8/8/94 jpa Added Outset method [1178690]
- <2> 6/18/94 MB Update memory includes
- <1> 6/15/94 jpa first checked in
-
- In Progress:
-
- */
-
-
- #ifndef _ALTPOINT_
- #include "AltPoint.h" /* Use C++ savvy ODPoint and ODRect*/
- #endif
-
- #ifndef _ALTPOLY_
- #include "AltPoly.h"
- #endif
-
- #ifndef _RGNSHPE_
- #include "RgnShpe.h"
- #endif
-
- #ifndef _POLYSHPE_
- #include "PolyShpe.h"
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include "Trnsform.xh"
- #endif
-
- #ifndef _RGN2PLYM_
- #include "Rgn2PlyM.h"
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- #ifndef _ODMATH_
- #include <ODMath.h>
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _UTILERRS_
- #include "UtilErrs.h"
- #endif
-
-
- RgnShape::RgnShape( ODGeometryMode mode )
- :RealShape(mode),
- fPolygon()
- {
- #if ODDebug
- fType = 1;
- #endif
- }
-
-
- RgnShape::~RgnShape( )
- {
- this->Purge(0);
- RealShape::Purge(0); // Dispose rgn too
- }
-
-
- ODSize
- RgnShape::Purge( ODSize )
- {
- // Don't dispose the region like my parent class!
- if( fPolygon.HasData() ) {
- ODSize size = fPolygon.GetDataSize();
- fPolygon.Clear();
- return size;
- } else
- return 0;
- }
-
-
- void
- RgnShape::GetBoundingBox( ODRect *bounds )
- {
- if( fQDRegion ) {
- Rect bbox = (**fQDRegion).rgnBBox;
- *bounds = bbox;
- } else
- bounds->Clear();
- }
-
-
- RealShape*
- RgnShape::SetRectangle( const ODRect *r )
- {
- if( !fQDRegion ) {
- fQDRegion = ODNewRgn();
- THROW_IF_NULL(fQDRegion);
- }
- Rect qdr;
- r->AsQDRect(qdr);
- RectRgn(fQDRegion,&qdr);
- this->Purge(0);
- return this;
- }
-
-
- RealShape*
- RgnShape::Clear( )
- {
- SetRectRgn(fQDRegion,0,0,0,0);
- this->Purge(0);
- return this;
- }
-
-
- void
- RgnShape::CopyPolygon( ODPolygon &poly )
- {
- if( !fPolygon.HasData() )
- Rgn2Poly(fQDRegion,fPolygon);
- poly.CopyFrom(fPolygon);
- }
-
-
- RealShape*
- RgnShape::SetPolygon( const ODPolygon &poly )
- {
- RgnHandle rgn = poly.AsQDRegion();
- this->Purge(0);
- fQDRegion = rgn;
-
- TRY{
- fPolygon.CopyFrom(poly);
- }CATCH_ALL{
- if( ErrorCode() == kODErrOutOfMemory )
- fPolygon.Clear(); // It's okay if poly couldn't be copied
- else
- RERAISE;
- }ENDTRY
-
- return this;
- }
-
-
- void
- RgnShape::InitQDRegion( )
- {
- }
-
-
- gxShape
- RgnShape::CopyGXShape( )
- {
- if( !fPolygon.HasData() )
- Rgn2Poly(fQDRegion,fPolygon);
- return fPolygon.AsGXShape();
- }
-
-
- void
- RgnShape::SetPlatformShape( ODGraphicsSystem system, ODPlatformShape shape )
- {
- ASSERT(system==kODQuickDraw,kODErrAssertionFailed);
- if( shape==kODNULL )
- THROW(kODErrInvalidPlatformShape);
-
- RealShape::Purge(0);
- fQDRegion = (RgnHandle)shape;
- }
-
-
- ODBoolean
- RgnShape::IsSameAs( RealShape *shape )
- {
- ASSERT_NOT_NULL(fQDRegion);
- if( shape==this )
- return kODTrue;
- Boolean empty = this->IsEmpty();
- Boolean shapeEmpty = shape->IsEmpty();
- if( empty || shapeEmpty )
- return empty==shapeEmpty;
-
- return EqualRgn(fQDRegion, (RgnHandle)shape->GetPlatformShape(kODQuickDraw));
- }
-
-
- ODBoolean
- RgnShape::IsEmpty( )
- {
- ASSERT_NOT_NULL(fQDRegion);
- return EmptyRgn(fQDRegion);
- }
-
-
- ODBoolean
- RgnShape::ContainsPoint( ODPoint point )
- {
- ASSERT_NOT_NULL(fQDRegion);
- return PtInRgn(point.AsQDPoint(),fQDRegion);
- }
-
-
- ODBoolean
- RgnShape::IsRectangular( )
- {
- ASSERT_NOT_NULL(fQDRegion);
- return GetHandleSize((Handle)fQDRegion)==sizeof(Region);
- // (Empty region has no extra data past the end of its struct.)
- }
-
-
- ODBoolean
- RgnShape::HasGeometry( )
- {
- return kODTrue /*this->IsRectangular()*/;
- }
-
-
- RealShape*
- RgnShape::Copy( )
- {
- ASSERT_NOT_NULL(fQDRegion);
- RgnHandle r = (RgnHandle) ODCopyHandle((ODHandle)fQDRegion);
- RgnShape* s;
- TRY{
- s = new RgnShape(fMode);
- }CATCH_ALL{
- DisposeRgn(r);
- RERAISE;
- }ENDTRY
- s->SetPlatformShape(kODQuickDraw,r);
- return s;
- }
-
-
- RealShape*
- RgnShape::Transform( Environment *ev, ODTransform *xform )
- {
- ASSERT_NOT_NULL(fQDRegion);
- if( !EmptyRgn(fQDRegion) )
- if( xform->IsQDOffset(ev) ) {
- Point offset = xform->GetQDOffset(ev);
- OffsetRgn(fQDRegion,offset.h,offset.v); // QD offset: just offset region
- if( fPolygon.HasData() )
- fPolygon.Transform(ev,xform); // ...and cached polygon (if any)
-
- } else {
- // Must promote myself to a polygon and try again.
- if( !fPolygon.HasData() )
- Rgn2Poly(fQDRegion,fPolygon);
- RealShape *polyShape = RealShape::NewGeometricShape(fMode);
- TRY{
- polyShape->SetPolygon(fPolygon); // fPolygon is always simple
- polyShape->Transform(ev,xform);
- }CATCH_ALL{
- delete polyShape;
- RERAISE;
- }ENDTRY
- delete this;
- return polyShape;
- }
-
- return this;
- }
-
-
- RealShape*
- RgnShape::Outset( ODCoordinate distance )
- {
- ASSERT_NOT_NULL(fQDRegion);
- if( !EmptyRgn(fQDRegion) ) {
- short intDist = ODFixedRound(-distance);
- InsetRgn(fQDRegion,intDist,intDist);
- this->Purge(0);
- }
- return this;
- }
-
-
- RealShape*
- RgnShape::Subtract( RealShape *shape )
- {
- ASSERT_NOT_NULL(fQDRegion);
- if( shape==this )
- return this->Clear();
- else if( !this->IsEmpty() && !shape->IsEmpty() ) {
- ODRect bounds;
- Rect b, sect;
- shape->GetBoundingBox(&bounds);
- bounds.AsQDRect(b);
- if( SectRect(&b,&(**fQDRegion).rgnBBox,§) ) {
- DiffRgn(fQDRegion, shape->GetQDRegion(), fQDRegion);
- this->Purge(0);
- }
- }
- return this;
- }
-
-
- RealShape*
- RgnShape::Intersect( RealShape *shape )
- {
- ASSERT_NOT_NULL(fQDRegion);
- if( shape!=this && !this->IsEmpty() ) {
- ODRect bounds;
- Rect b, sect;
- shape->GetBoundingBox(&bounds);
- bounds.AsQDRect(b);
- if( !bounds.IsEmpty() && SectRect(&b,&(**fQDRegion).rgnBBox,§) )
- SectRgn(fQDRegion, shape->GetQDRegion(), fQDRegion);
- else
- SetRectRgn(fQDRegion, 0,0,0,0);
- this->Purge(0);
- }
- return this;
- }
-
-
- RealShape*
- RgnShape::Union( RealShape *shape )
- {
- ASSERT_NOT_NULL(fQDRegion);
- if( shape!=this && !shape->IsEmpty() ) {
- UnionRgn(fQDRegion, shape->GetQDRegion(), fQDRegion);
- this->Purge(0);
- }
- return this;
- }
-